package com.migo.api;

import com.migo.annotation.IgnoreAuth;
import com.migo.entity.AppDownloadEntity;
import com.migo.entity.MgMarketingBannerEntity;
import com.migo.entity.TechnicalSupportTypeEntity;
import com.migo.oss.OSSFactory;
import com.migo.service.FeedbackService;
import com.migo.service.MgMarketingBannerService;
import com.migo.service.SysOssService;
import com.migo.thread.FeedbackThread;
import com.migo.utils.R;
import com.migo.utils.ThreadPoolUtils;
import com.migo.utils.redis.RedisCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

/**
 * APP手机 广告banner
 */
@RestController
@RequestMapping("/api")
public class ApiMarketingBannerController extends ApiBaseController {


    @Autowired
    private MgMarketingBannerService mgMarketingBannerService;

    @Autowired
    private RedisCacheUtil<List<MgMarketingBannerEntity>> redisCacheUtil;

    /**
     * 创建意见反馈
     */
    @IgnoreAuth
    @RequestMapping("/queryMarketingBanner")
    public R queryMarketingBanner(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("countryCode")||!params.containsKey("version")) {
            params.put("countryCode", "CN");
            params.put("version", "");
        }
        String key = "queryMarketingBanner_" + params.get("countryCode")+"_version_"+params.get("version");
        //缓存部分 开始
        List<MgMarketingBannerEntity> mgMarketingBannerEntityList = null;
        if (redisCacheUtil.hashKey(key)) {
            mgMarketingBannerEntityList = redisCacheUtil.getCacheList(key);
        } else {
            //查询数据库写入redis
            synchronized (this) {
                mgMarketingBannerEntityList = mgMarketingBannerService.queryList(params);
                redisCacheUtil.setCacheList(key, mgMarketingBannerEntityList);
            }
        }
        return R.ok().put("data", mgMarketingBannerEntityList);
    }


}
